﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WodLib
{
    [Serializable()]
    public class Item : DimensionalObject, IAttackable, ICloneable, IEffectable
    {
        /// <summary>
        /// Creates default item.
        /// </summary>
        public Item()
        {
            EffectsList = new List<Effect>();
        }
        
        /// <summary>
        /// Creates item with given durability and size.
        /// </summary>
        /// <param name="durability">Durability of new item</param>
        /// <param name="size">Size of new item</param>
        public Item(int durability, int size):this()
        {
            Durability = durability;
            Size = size;
            Structure = Size + Durability;
        }

        /// <summary>
        /// Durability of object
        /// </summary>
        public int Durability
        {
            get;
            set;
        }

        private int damageDealed = 0;

        //Durability + Size
        /// <summary>
        /// Current structure points
        /// </summary>
        public int Structure
        {
            get
            {
                return Durability + Size - damageDealed;
            }
            set
            {
                damageDealed = Durability + Size - value;
            }
        }

        /// <summary>
        /// Strength required to use item effectively
        /// </summary>
        [System.ComponentModel.ReadOnly(true)]
        public virtual int Strength
        {
            get
            {
                return Size;               
            }
            set
            {
                
            }
        }

        /// <summary>
        /// Dice roll attack bonus.
        /// </summary>
        [System.ComponentModel.ReadOnly(true)]
        public virtual int Damage
        {
            get
            {
                return Math.Min(Durability, Size);
            }
            set
            {
            }
        }

        public virtual object Clone()
        {
            Item tmp = (Item)this.MemberwiseClone();
            tmp.EffectsList = new List<Effect>(this.EffectsList.Capacity);
            foreach (var item in this.EffectsList)
            {
                tmp.EffectsList.Add((WodLib.Effect)item.Clone());
            }
            return tmp;
        }

        #region IEffectable Members
        [System.ComponentModel.Editor(typeof(WodLib.Controls.WodCollectionEditor<Effect>),
             typeof(System.Drawing.Design.UITypeEditor))]
        public List<Effect> EffectsList
        {
            get;
            set;
        }

        #endregion

        protected int diceBonus = 0;

        public virtual int DiceBonus
        {
            get
            {
                int dicePenalty = Durability - damageDealed;
                if (dicePenalty > 0)
                    dicePenalty = 0;
                return diceBonus + dicePenalty;
            }
            set
            {
                diceBonus = value;
            }
        }
    }
}
